package com.luo.backend.controller;

import com.luo.backend.common.ApiResponse;
import com.luo.backend.dto.CategoryResponse;
import com.luo.backend.service.CategoryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 分类管理接口
 */
@RestController
@RequestMapping("/api/v1")
public class CategoryController {
    
    private static final Logger logger = LoggerFactory.getLogger(CategoryController.class);
    
    @Autowired
    private CategoryService categoryService;
    
    /**
     * 获取所有分类列表
     * GET /api/v1/categories
     */
    @GetMapping("/categories")
    public ApiResponse<List<CategoryResponse>> getCategories() {
        try {
            List<CategoryResponse> categories = categoryService.getAllCategories();
            return ApiResponse.success(categories);
        } catch (Exception e) {
            logger.error("获取分类列表失败", e);
            return ApiResponse.error("获取分类列表失败：" + e.getMessage());
        }
    }
}






